<!--
 * @Author: houmin 745762351@qq.com
 * @Date: 2023-09-11 09:50:52
 * @LastEditors: houmin 745762351@qq.com
 * @LastEditTime: 2023-12-02 21:14:28
 * @FilePath: \tch-h5\src\views\hotel-detail\HotelDetail.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
  <Header title="入园码" :back="true" />
  <div class="input-code">
    <template v-if="!qr">
      <div class="no-data">
        <img src="../../assets/images/icons/no-card-bg.png" width="56" alt="" />
        <p>您还没有购买年卡</p>
      </div>
      <van-button
        class="btn"
        @click="
          () =>
            router.push('/')
        "
        >购买年卡</van-button
      >
              <!-- query: route?.query?.cardId, -->
    </template>
    <template v-else>
      <p>
        <span class="my-card">我的入园码</span>
      </p>
      <div class="qr">
        <img :src="qr" width="150" alt="" />
      </div>
      <p class="footer mt32">有效期至：{{ expireTime }}</p>
      <p class="footer" @click="getData">点击刷新</p>
    </template>
  </div>
</template>

<script setup>
import { ref } from "vue";
import { useRouter } from "vue-router";
import Header from "@/components/header/Header.vue";
import api from "@/api/index.js";
import QRCode from "qrcode";
const router = useRouter();
const qr = ref("");
const expireTime = ref("");

const getData = async () => {
  const { code, data } = await api.getMyCode();
  if (code == 200) {
    expireTime.value = data?.expireTime || "";
    QRCode.toDataURL(data?.activateCode || "")
      .then((url) => {
        qr.value = url || "";
      })
      .catch((err) => {
        console.error(err);
      });
  }
};
getData();

</script>

<style lang="scss" scoped>
.input-code {
  width: 100%;
  height: 100%;
  background: url("../../assets/images/oneCard/bg.png") no-repeat;
  background-size: contain;
  text-align: center;
  .no-data {
    padding-top: 25vh;
    font-size: 1.2rem;
    color: rgba(139, 139, 139, 1);
    p {
      margin-top: 1rem;
    }
  }
  .btn {
    margin-top: 12rem;
    width: 10.6rem;
    height: 3.4rem;
    border-radius: 5px;
    background: rgba(79, 172, 145, 1);
    padding: 5px 15px 5px 15px;
    color: #fff;
    border: none;
  }
  .my-card {
    display: inline-block;
    width: 110px;
    height: 28px;
    line-height: 28px;
    border-radius: 5px;
    background: rgba(79, 172, 145, 1);
    padding: 5px 15px 5px 15px;
    color: #fff;
    margin-top: 4rem;
    font-size: 1.6rem;
  }
  .qr {
    margin-top: 2rem;
    img {
      border: 0.3rem rgba(79, 172, 145, 1) solid;
    }
  }
  .footer {
    font-size: 1.4rem;
    line-height: 1.5;
  }
  .mt32 {
    margin-top: 3.2rem;
  }
}
</style>